import React, { useEffect, useState } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { Card, Descriptions, Button } from 'antd'
import { IhospitalShow } from '@api/hospital/hospitalList/model/hospitalListTypes'
import { reqGetHospitalShow } from '@api/hospital/hospitalList'
export default function HospitalShow() {
  const navigate = useNavigate()
  // 解构重命名
  const { state: id } = useLocation()

  const [hospitalShow, setHospitalShow] = useState<IhospitalShow>({})
  useEffect(() => {
    async function fetch() {
      const result = await reqGetHospitalShow(id as string)
      setHospitalShow(result)
    }
    fetch()
  }, [])

  return (
    <Card>
      <Descriptions title="基本信息" bordered column={2}>
        <Descriptions.Item label="医院名称">
          {hospitalShow.hospital?.hosname}
        </Descriptions.Item>
        <Descriptions.Item label="医院logo">
          <img
            src={'data:image/png;base64,' + hospitalShow.hospital?.logoData}
            alt=""
            width="80"
          />
        </Descriptions.Item>
        <Descriptions.Item label="医院编码">
          {hospitalShow.hospital?.hoscode}
        </Descriptions.Item>
        <Descriptions.Item label="医院地址">
          {hospitalShow.hospital?.param.fullAddress}
        </Descriptions.Item>
        {/* span表示这一列占一行中的几个位置. 默认有3个位置,但是在Descriptions, 通过column改为了2个 */}
        <Descriptions.Item label="坐车路线" span={2}>
          {hospitalShow.hospital?.route}
        </Descriptions.Item>
        <Descriptions.Item label="医院简介" span={2}>
          {hospitalShow.hospital?.intro}
        </Descriptions.Item>
      </Descriptions>
      <Descriptions
        title="预约规则信息"
        bordered
        column={2}
        style={{ marginTop: 20, marginBottom: 20 }}
      >
        <Descriptions.Item label="预约周期">
          {hospitalShow.bookingRule?.cycle}天
        </Descriptions.Item>
        <Descriptions.Item label="放号时间">
          {hospitalShow.bookingRule?.releaseTime}
        </Descriptions.Item>
        <Descriptions.Item label="停挂时间">
          {hospitalShow.bookingRule?.stopTime}
        </Descriptions.Item>
        <Descriptions.Item label="退号时间">
          {hospitalShow.bookingRule?.quitTime}
        </Descriptions.Item>
        {/* span表示这一列占一行中的几个位置. 默认有3个位置,但是在Descriptions, 通过column改为了2个 */}
        <Descriptions.Item label="预约规则" span={2}>
          {hospitalShow.bookingRule?.rule.map((item, index) => {
            return (
              <div key={index}>
                {index + 1}: {item}
              </div>
            )
          })}
        </Descriptions.Item>
      </Descriptions>
      <Button
        onClick={() => {
          navigate(-1)
        }}
      >
        返回
      </Button>
    </Card>
  )
}
